package fr.umlv.ig.metroApplication;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;

import fr.umlv.ig.extraWindows.AboutWindow;
import fr.umlv.ig.extraWindows.HelpWindow;
import fr.umlv.ig.metroFactory.GraphicFactory;
import fr.umlv.ig.model.MetroModelImpl;

/**
 * This class represents the menu of the main window of the application.
 * 
 * @author Jenseric Catbagan
 * @author william Choy
 */
class MetroApplicationMenu {
	
	/**
	 * Returns the JMenuBar of the application.
	 * @param frame the frame which contains the application.
	 * @param metroModel the {@link MetroModelImpl} used in the application.
	 * @return the JMenuBar of the application.
	 */
	static JMenuBar getMetroMenuBar(JFrame frame, MetroModelImpl metroModel, ActionListener toolWindow) {
		JMenuBar menuBar = new JMenuBar();
		menuBar.add(getMenuMetro(frame, metroModel, toolWindow));
		menuBar.add(getHelpMenu(frame));
		return menuBar;
	}

	/**
	 * Returns the menu metro of the application.
	 * @param frame the frame which contains the application.
	 * @param metroModel the {@link MetroModelImpl} used in the application.
	 * @return the JMenu for the menu Application.
	 */
	static JMenu getMenuMetro(final JFrame frame, final MetroModelImpl metroModel, final ActionListener toolWindow) {
		JMenu menu = new JMenu("Application");
		
		JMenuItem trainsConfig = new JMenuItem("Line Configuration");
		trainsConfig.setIcon(GraphicFactory.ICONTOOL);
		trainsConfig.setMnemonic(KeyEvent.VK_T);
		trainsConfig.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, InputEvent.CTRL_MASK));
//		trainsConfig.addActionListener(new ActionListener() {
//			@Override
//			public void actionPerformed(ActionEvent e) {
//				if(cw==null) {
//					cw = new ConfigurationWindow(frame, "Train Config", metroModel);
//				}
//				cw.start();
//			}
//		});
		trainsConfig.addActionListener(toolWindow);
		menu.add(trainsConfig);
		return menu;
	}
	
	/**
	 * Returns the menu help of the application.
	 * @param frame the frame which contains the application.
	 * @param metroModel the {@link MetroModelImpl} used in the application.
	 * @return the JMenu for the menu ^Help.
	 */
	static JMenu getHelpMenu(final JFrame frame) {
		JMenu menuHelp = new JMenu("Help");
		menuHelp.setMnemonic(KeyEvent.VK_I);
		
		JMenuItem help = new JMenuItem("Help");
		help.setIcon(GraphicFactory.ICONHELP);
		
		help.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, InputEvent.ALT_DOWN_MASK));
		help.addActionListener(new ActionListener() {
			HelpWindow hw;
			@Override
			public void actionPerformed(ActionEvent e) {
				if(hw==null) {
					hw = new HelpWindow(frame);
				}
				hw.start();
			}
		});
		
		
		JMenuItem about = new JMenuItem("About");
		about.setIcon(GraphicFactory.ICONABOUT);
		
		about.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F2, InputEvent.ALT_DOWN_MASK));
		about.addActionListener(new ActionListener() {
			AboutWindow aw;
			@Override
			public void actionPerformed(ActionEvent e) {
				if(aw==null) {
					aw = new AboutWindow(frame);
				}
				aw.start();
			}
		});
	
		menuHelp.add(help);
		menuHelp.add(about);
		return menuHelp;
	}
	
	
	

}
